FAQs - II
Primary memory should provide:
Paging divides logical memory into fixed-size pages and physical memory into equal-size frames. A page table maps each logical page to a physical frame.
Conceptually:
| Logical Address | ||
| Page | Offset | |
| | | ||
| Page Table | ||
| Page 0 ----> | Frame 5 | |
| Page 1 ----> | Frame 2 | |
| Page 2 ----> | Frame 7 | |
| Page 3 ----> | Frame 1 | |
| | | ||
| Physical Memory | ||
| Frame 0 | ||
| Frame 1 | Page 3 | |
| Frame 2 | Page 1 | |
| Frame 3 | ||
| Frame 4 | ||
| Frame 5 | Page 0 | |
| Frame 6 | ||
| Frame 7 | Page 2 | |
The logical address consists of:
Page number + Offset
The page number is used to index the page table, which gives the corresponding frame number. The frame number and offset form the physical address.
Advantages
| Paging | Segmenation |
|---|---|
| Memory divided into fixed-size pages | Memory divided into variable-size segments|
| Physical memory divided into frames | Physical memory does not required fixed-size units. |
| Programmer usually does not see pages | Segments represent logical program units |
| Can cause internal fragmentation | Can cause external fragmentation |
| Address = page number + offset | Address = segment number + offset |
| Mainly supports physical memory management | Represents logical divisions such as code, date, stack |
Answer: The major file allocation methods are:
| Sequential Access | Random Access |
|---|---|
| Data is accessed in order | Data can be accessed directly |
| To reach a later record, earlier records may need to be processed | A particular location can be accessed directly. |
| Suitable for tapes and sequential processing | Suitable for disks and databases |
| Generally simpler | Requires direct positioning / indexing |
A directory is a file-system structure that stores information about files and possibly other directories. It can contain:
Answer: FAT (File Allocation Table) is a file-system structure in which a table records the allocation and linkage of disk clusters. A simplified FAT structure is:
| Boot / Reserved Area |
| File Allocation Table |
| Root Directory |
| Data Area |
| Clsuter 2 |
| Clsuter 3 |
| Clsuter 4 |
| Clsuter 5 |
| Cluster | FAT Entry |
|---|---|
| 2 | 5 |
| 5 | 8 |
| 8 | EOF |
The OS must maintain information about which disk blocks are free and which are allocated. Common techniques include:
Block: 0 1 2 3 4 5 6 7
Bit: 1 0 0 1 1 0 0 1
For example, if 0 = free and 1 = allocated, blocks 1, 2, 5, and 6 are free.
Free Block --> Block 4 --> Block 8 --> Block 15 --> Block 21
Answer : A deadlock is a situation in which a group of processes is permanently blocked because each process is waiting for a resource held by another process in the group. Example:
Neither process can process. The four necessary conditions for deadlock are:
Answer: The Banker's algorithm is a deadlock-avoidance algorithm. It checks whether granting a resource request will leave the system in a safe state. It requires information about:
if Resource Available:
check if P1 can finish?
if yes
release resources
check if P2 can finish?
else try P2
The algorithm grants a request only if the resulting state remains safe.
Answer: Prevention ensures that at least one of the four necessary deadlock conditions cannot occur. For example:
Deadlock Avoidance: The OS examines resource requests before granting them. It ensures that the system remains in a safe state. Example: Banker's algorithm.
Deadlock Detection: The OS allows deadlocks to occur and periodically checks whether one has occurred. Methods include:
Deadlock: After detecting deadlock, the OS can recover by: